window.addEventListener("load", function () {
	//btn1点击事件
	$("#btn1").addEventListener("click", function () {
		let num = 60;
		$("#btn1").disabled = true;
		$("#forbidden>input").disabled = true;
		let time = window.setInterval(function () {
			$("#btn1").style.width = "84px";
			num--;
			$("#btn1").innerHTML = num;
			if (num <= 0) {
				clearInterval(time);
				$("#btn1").disabled = false;
				$("#forbidden>input").disabled = false;
				$("#btn1").innerHTML = "获取验证码";
			}
		}, 1000);
	});





	//inp判断
	$("#btn2").addEventListener("click", function (e) {
		const usernameValue = $("#userName").value;
		const telNumValue = $("#telNum").value;
		const codeValue = $("#code").value;
		const passwordValue = $("#passWord").value;
		e.preventDefault()
		// 用户名判断
		if (usernameValue.length < 6 || usernameValue.length > 20) {
			$("#userName").style.border = "1px solid red";
			$("#userName").nextElementSibling.innerHTML =
				"昵称需在6-12位字母数之间";
			$("#userName").nextElementSibling.style.color = "red";
			
		} else {
			$("#userName").style.border = "1px solid #ccc";
			$("#userName").nextElementSibling.textContent = "";
		}
		// 手机号判断
		if (telNumValue.length != 11) {
			$("#telNum").style.border = "1px solid red";
			$("#telNum").nextElementSibling.innerHTML = "手机号码需11位";
			$("#telNum").nextElementSibling.style.color = "red";
		} else {
			$("#telNum").style.border = "1px solid #ccc";
			$("#telNum").nextElementSibling.textContent = "";
		}
		// 验证码判断
		if (codeValue.length != 4) {
			$("#code").style.border = "1px solid red";
			$("#code").nextElementSibling.innerHTML = "&nbsp;验证码输入错误";
			$("#code").nextElementSibling.style.color = "red";
		} else {
			$("#code").style.border = "1px solid #ccc";
			$("#code").nextElementSibling.textContent = "";
		}
		// 密码判断
		if (passwordValue.length < 6 || passwordValue.length > 12) {
			$("#passWord").style.border = "1px solid red";
			$("#passWord").nextElementSibling.innerHTML =
				"密码需在6-12位字母数之间";
			$("#passWord").nextElementSibling.style.color = "red";
		} else {
			$("#passWord").style.border = "1px solid #ccc";
			$("#passWord").nextElementSibling.textContent = "";
		}
		
	});
	
	//btn2的点击激活样式
	let flag = true;

	$("#affirm").addEventListener("click", function () {
		if (flag) {
			
			$("#btn2").style.backgroundColor = "#03c5ff";
			$("#btn2").style.color = "#fff";
		} else {
			$("#btn2").style.backgroundColor = "#e0e0e0";
			$("#btn2").style.color = "#000";
		}
		flag = !flag;
	});
});
